import request from '@/sheep/request/association.js';
import {
	baseUrl,
	platformToken,
	platform as pl
} from '@/sheep/config/association.js';
import association from '@/sheep/store/association.js';


export default {
	// 分享
	send_share: (data) =>
		request({
			url: 'api/share/shareGoods',
			method: 'POST',
			data,
			custom: {
				auth: true,
			},
		}),
	

	// 登录接口
	loginApi: () =>
		request({
			url: 'api/user/thirdLogin',
			method: 'GET',
			header: {
				Authorization: uni.getStorageSync(platformToken),
			},
			custom: {
				auth: true,
			},
		}),
	// 登录方法
	login: async () => await association().login(),
	// 首页小程序列表
	index: (platform = pl, data) =>
		request({
			url: 'api/index/index',
			method: 'GET',
			data,
			platform
		}),
	// 获取二级分类
	getCategory: (data) =>
		request({
			url: 'api/index/getCategory',
			method: 'GET',
			data,
		}),
	//获取话题列表
	gettalkList: (data) =>
		request({
			url: 'api/topic/list',
			method: 'GET',
			data,
		}),
	// 话题详情
	topicDetails: (data) =>
		request({
			url: 'api/topic/details',
			method: 'GET',
			data,
		}),
	// 话题收藏和取消收藏
	topicCollection: (data) =>
		request({
			url: 'api/topic/collection',
			method: 'POST',
			data,
			custom: {
				auth: true,
			},
		}),
	// 话题转发记录
	topicForward: (data) =>
		request({
			url: 'api/topic/forward',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 话题评论
	topicComment: (data) =>
		request({
			url: 'api/topic/comment',
			method: 'POST',
			data,
			custom: {
				auth: true,
			},
		}),
	// 话题删除我的评论
	topicDelComment: (data) =>
		request({
			url: 'api/topic/delComment',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 话题点赞&&取消
	topicLike: (data) =>
		request({
			url: 'api/topic/topicLike',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 发现详情
	getFindDetails: (data) =>
		request({
			url: 'api/find_new/details',
			method: 'GET',
			data,
		}),
	// 发现列表
	getfindList: (data) =>
		request({
			url: 'api/find_new/listNew',
			method: 'GET',
			data,
		}),
	// 话题点赞&&取消
	findLike: (data) =>
		request({
			url: 'api/find/like',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 广场列表
	getsquareList: (data) =>
		request({
			url: 'api/find_new/listNew',
			method: 'GET',
			header: {
				platform: ''
			},
			data: {
				type: "all",
				...data
			},
		}),
	//发现评论
	findComment: (data) =>
		request({
			url: 'api/find/comment',
			method: 'POST',
			data,
			custom: {
				auth: true,
			},
		}),
	// 发现转发记录
	findForward: (data) =>
		request({
			url: 'api/find/forward',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 发现删除我的评论
	findDelComment: (data) =>
		request({
			url: 'api/find/delComment',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 发现评论点赞
	findCommentLike: (data) =>
		request({
			url: 'api/find/commentLike',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 发现文章收藏&&取消
	findCollection: (data) =>
		request({
			url: 'api/find/collection',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 查询平台对应下的商品、团购、门店列表
	getPromotionInfo: (data) =>
		request({
			url: 'api/find/getPromotionInfo',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 发布(续写)日记 、 等发现文章
	addFind: (data) =>
		request({
			url: 'api/find_new/addFind',
			method: 'POST',
			data,
			custom: {
				auth: true,
			},
		}),
	// 删除发现文章
	delFind: (data) =>
		request({
			url: 'api/find/delFind',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	// 我的发现文章列表
	myFindList: (data) =>
		request({
			url: 'api/find/myFindList',
			method: 'GET',
			data,
			custom: {
				auth: true,
			},
		}),
	//上传
	upload: (file) => {
		// const token = uni.getStorageSync('petToken');
		// uni.showLoading({
		// 	title: '上传中',
		// });
		// console.log(file);
		return new Promise((resolve, reject) => {

			uni.uploadFile({
				url: baseUrl + 'api/common/upload',
				filePath: file,
				name: 'file',
				header: {
					Accept: 'text/json',
					token: uni.getStorageSync('associationToken'),
				},
				success: (uploadFileRes) => {
					console.log("uploadFileRes:", uploadFileRes);
					let result = JSON.parse(uploadFileRes.data);
					if (result.code == 1) {
						resolve(result.data);
					} else {
						uni.showToast({
							icon: 'none',
							title: result.msg,
						});
						resolve(false)
					}
				},
				fail: (error) => {
					console.log('上传失败：', error);
					return resolve(false);
				},
				complete: () => {
					// uni.hideLoading();
				},
			});
		});
	},
	info: {
		getInfo: (data) =>
			request({
				url: 'api/index/getInfo',
				method: 'GET',
				data,
				custom: {
					showError: false,
					auth: true,
				},
			}),
		collection: (data) =>
			request({
				url: 'api/find/collection',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		operate: (data) =>
			request({
				url: 'api/care/operate',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		careList: (data) =>
			request({
				url: 'api/care/careList',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		fansList: (data) =>
			request({
				url: 'api/care/fansList',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		detail: (data) =>
			request({
				url: 'api/find/detail',
				method: 'POST',
				data,
				custom: {
					auth: true,
				},
			}),
		collectionList: (data) =>
			request({
				url: 'api/find/collectionList',
				method: 'POST',
				data,
				custom: {
					auth: true,
				},
			}),
	},
	// 新增接口
	publish: {
		// 获取主题
		subject: (data) =>
			request({
				url: 'api/tag/list',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		friend: (data) =>
			request({
				url: 'api/tag/getFriendsList',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
	},
	// 新增 个人中心
	user: {
		details: (data) =>
			request({
				url: 'api/my_find/index',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		follow: (data) =>
			request({
				url: 'api/my_find/care',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		list: (data) =>
			request({
				url: 'api/my_find/list',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		info: (data) =>
			request({
				url: 'api/my_find/profile',
				method: 'GET',
				data,
				custom: {
					auth: true,
				},
			}),
		edit_info: (data) =>
			request({
				url: 'api/user/profile',
				method: 'POST',
				data,
				custom: {
					auth: true,
				},
			}),
		categoryList: () =>
			request({
				url: 'api/my_find/category',
				method: 'GET',
				custom: {
					auth: true,
				},
			}),
	}
};